﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Runda.CMS.Order.Entity;
using Runda.CMS.Common.Utility;
using System.Linq.Expressions;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Runda.CMS.Order.Repository
{
    public class InventoryRepository
    {
        private string db = ConfigurationManager.ConnectionStrings["OrderConnectionString"].ConnectionString;

        public Inventory findInventoryByBarCode(String inventoryId)
        {
            using (OrderDataContext context = new OrderDataContext(db))
            {
                bool isExist = context.inventory.Any(inventory => inventory.id == inventoryId);
                if (isExist)
                {
                    Inventory at = context.inventory.Single(inventory => inventory.id == inventoryId);
                    return at;
                }
                return null;
            }
        }

        public Inventory findInventoryBycInvCode(String cInvCode)
        {
            using (OrderDataContext context = new OrderDataContext(db))
            {
                bool isExist = context.inventory.Any(inventory => inventory.batchCode == cInvCode);
                if (isExist)
                {
                    Inventory at = context.inventory.Single(inventory => inventory.batchCode == cInvCode);
                    return at;
                }
                return null;
            }
        }
    }
}
